<?php
/**
 * Created by PhpStorm.
 * User: yangyulu
 * Date: 2020/3/10
 * Time: 上午11:53
 */
class Admin_questionsController extends Admin_baseController{
    public function listAction(){
        $page = Request::getParams('page', 1);
        $pageSize = Request::getParams('pageSize', 20);
        $name=Request::getParams("name");
        $where = $value = $url = array();
        if ($name) {
            $where[] = 'problem like ?';
            $value[] = '%' . $name . '%';
            $url['name'] = $name;
        }
        $total = self::model('questions')->count('id', $where, $value);
        $list = self::model('questions')->limit(($page - 1) * $pageSize, $pageSize)->order('id desc')->getAll($where, $value);
        $this->assign(array(
            'page' => $page,
            'pageSize' => $pageSize,
            'name' => $name,
            'total' => $total,
            'list' => $list,
            'pageHtml' => self::instance('Pagination')->page($page)->num($pageSize)->total($total)->url(Router::getBaseUrl() . '/admin_questions/list?' . ($url ? http_build_query($url) : '') . '&page=')->rendHtml(),
        ));
        $this->display();
    }

    public function applyAction(){
        $ids=Request::getParams('ids');
        $info= self::model('questions')->getOne(["id=?","status=?"],[$ids,0]);
        if(empty($info)){
            Response::showMsg('信息不存在，无法前台显示');
        }
        $res=self::model('questions')->update(["status"=>1],"id=?",$ids);
        if($res){
            self::model("questions")->medal($info["user_id"]);
            Response::ajax(200, "前台显示成功");
        }else{
            Response::showMsg('前台显示失败');
        }

    }
}